CODE:
def get_ssl_details(domain): context = ssl.create_default_context() conn = context.wrap_socket(socket.socket(socket.AF_INET), server_hostname=domain) conn.connect((domain, 443)) cert = conn.getpeercert() issuer = dict(x[0] for x in cert['issuer']) subject = dict(x[0] for x in cert['subject']) expire_date = datetime.datetime.strptime(cert['notAfter'], '%b %d %H:%M:%S %Y %Z') days_remaining=expire_date-datetime.datetime.utcnow() return { 'issuer': issuer, 'subject': subject, 'expire_date': expire_date, 'days_remain':days_remaining }
When I m running the above code and entering the input domain https://www.chiptrolls.com/ . I got this following error while running the python program "socket.gaierror: [Errno 11001] getaddrinfo failed".
SOLUTION:
conn.connect((domain, 443)) expects only domain from the URL without the (http or https) protocol. So the below code extract the domain from the input URL from https://www.chiptrolls.com/ to www.chiptrolls.com.
parsed_url=urlparse(domain) domain=parsed_url.netloc
VIDEO GUIDE:
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article